﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>培训课程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../../static/css/font.css" rel="stylesheet" />
    <link href="../../static/css/weadmin.css" rel="stylesheet" />
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../../../lib/layui/layui.js"></script>
    <style>
        .layui-textarea-md {
            width: 100%;
            height: auto;
            overflow-y: hidden;
        }
    </style>
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">学习会</a><span lay-separator="">/</span>
            <a><cite>学习会课程设置</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="layui-fluid" id="infos">
        <table id="dataList" lay-filter="dataList"></table>
    </div>
    <div class="layui-fluid fluid-position">
        <div class="layui-form">
            <div class="layui-card">
                <div class="layui-card-header">
                    <div class="layui-row layui-col-space10 layui-btn-container">

                        <button type="button" class="layui-btn layui-btn-primary" id="find" name="查询"><i class="layui-icon">&#xe615;</i>查询</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="reset" name="清空"><i class="layui-icon">&#xe669;</i>清空</button>
                        <!--<button type="button" class="layui-btn layui-btn-normal" id="add" name="添加保存"><i class="layui-icon">&#xe608;</i> 添加保存</button>-->

                        <button type="button" class="layui-btn layui-btn-normal" id="edit" lay-filter="edit" name="保存" lay-submit><i class="layui-icon">&#xe642;</i>保存</button>
                        <button type="button" class="layui-btn layui-btn-danger" id="del" name="删除"><i class="layui-icon">&#xe640;</i>删除</button>
                        <button type="button" class="layui-btn layui-btn-warm" id="check" name="审核"><i class="layui-icon">&#xe605;</i>审核</button>
                        <button type="button" class="layui-btn layui-btn-warm" id="uncheck" name="取消审核"><i class="layui-icon">&#x1006;</i>取消审核</button>
                        <!--<button type="button" class="layui-btn layui-btn-warm layui-bg-cyan" id="release" name="发布"><i class="layui-icon">&#xe609;</i>发布</button>
                        <button type="button" class="layui-btn layui-btn-warm layui-bg-cyan" id="unrelease" name="取消发布"><i class="layui-icon">&#xe604;</i>取消发布</button>-->
                        <!--<button type="button" class="layui-btn" name="导入"><i class="layui-icon">&#xe638;</i>导入</button>
                        <button type="button" class="layui-btn" name="导出"><i class="layui-icon">&#xe632;</i>导出</button>
                        <button type="button" class="layui-btn" name="打印"><i class="layui-icon">&#xe63c;</i>打印</button>-->
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-collapse" lay-filter="infos_form">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">培训课程</h2>
                            <div class="layui-colla-content layui-show">
                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">基本信息</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-form layui-form-pane">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">课程名称</label>
                                                <div class="layui-input-block">
                                                    <input type="text" placeholder="课程名称" maxlength="50" class="layui-input" id="TCOName" name="TCOName" />
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">培训计划</label>
                                                <div class="layui-input-inline lay-ele-row3">
                                                    <input type="text" placeholder="选择计划" maxlength="50" class="layui-input " id="PrePlanName" name="PrePlanName" />
                                                </div>
                                                <div class="layui-input-inline lay-ele-row4">
                                                    <div id="download">
                                                    </div>
                                                </div>

                                            </div>

                                            <!--时间-->
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">培训教师</label>
                                                <div class="layui-input-inline">
                                                    <select id="TrainTeacherName" name="TrainTeacherName" lay-filter="TrainTeacherName">
                                                        <option value=""></option>

                                                    </select>
                                                </div>

                                                <label class="layui-form-label">教室</label>
                                                <div class="layui-input-inline">
                                                    <select id="CRName" name="CRName" lay-filter="CRName">
                                                        <option value=""></option>

                                                    </select>
                                                </div>
                                                <div class="layui-inline">
                                                    <label class="layui-form-label">起止时间</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" class="layui-input" id="StartDateTime" />
                                                    </div>

                                                    <label class="layui-form-label layui-form-label-inner layui-form-label-inner-w1">至</label>
                                                    <div class="layui-input-inline layui-form-label-inner">
                                                        <input type="text" class="layui-input" id="EndDateTime" name="EndDateTime" />
                                                    </div>
                                                    <div class="layui-input-inline">
                                                        <input type="text" class="layui-input" id="start" name="time" />
                                                    </div>
                                                    <div class="layui-input-inline layui-form-label-inner">
                                                        <input type="text" class="layui-input" id="end" name="time" />
                                                    </div>
                                                </div>
                                                <div class="layui-inline">
                                                    <label class="layui-form-label">时长(分钟)</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" class="layui-input" id="Duration" maxlength="3" disabled />
                                                    </div>
                                                </div>

                                                <!--<div class="layui-inline">
                                                    <label class="layui-form-label">发布</label>
                                                    <div class="layui-input-block">
                                                        <select id="IsRelease" class="layui-tree-more" name="IsRelease">
                                                            <option value="">请选择</option>
                                                            <option value="0">未发布</option>
                                                            <option value="1">已发布</option>
                                                        </select>
                                                    </div>
                                                </div>-->

                                            </div>

                                            <div class="layui-form-item" id="selectDeptShow">
                                                <div class="layui-form-label">选择部门</div>
                                                <div class="layui-input-block">
                                                    <input type="text" autocomplete="off" readonly="" id="selectDatas" name="selectDatas" placeholder="请选择" class="layui-input" />
                                                    <div class="eleTree" id="eleTree" lay-filter="data5"></div>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <div class="layui-form-label">参培人员</div>
                                                <div class="layui-input-block">
                                                    <input type="text" autocomplete="off" readonly="" id="selectDatas2" name="selectDatas2" placeholder="请选择" class="layui-input" />
                                                    <!--<div class="eleTree2" id="eleTree2" lay-filter="data6"></div>-->
                                                    <div class="layui-tab lay-ele-row2" id="persontabSearch" style="float:left;border:0px solid #f00;display:none;">
                                                        <div class="layui-form-item layui-search">
                                                            <input type="text" placeholder="输入姓名搜索" id="searchName" class="layui-input" />
                                                            <button type="button" class="layui-btn layui-btn-primary" id="findperson" name="查询"><i class="layui-icon" style="margin-left:-10px"></i>查询</button>
                                                            <div class="layui-input-inline" id="PersonContent1">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div style="clear:both"></div>
                                                    <div class="layui-tab lay-ele-row1" id="persontab" style="display:none;">
                                                        <!--<ul class="layui-tab-title" id="Persontitle"></ul>
                                                        <div class="layui-tab-content" id="PersonContent"></div>-->

                                                        <div id="AllPerson" style="width:150%;border:0px solid #f00">
                                                            <!--<div>第一组</div>
                                                            <div class="layui-tab-item layui-form layui-show">
                                                                <input type="checkbox" lay-skin="primary" value="" title="全选" name="person" lay-filter="deptradio" id="z0" />
                                                                <input type="checkbox" lay-skin="primary" value="3917317" title="安泽鑫1" name="person" lay-filter="deptradio" tag="z0i" />
                                                                <input type="checkbox" lay-skin="primary" value="3919316" title="高格" name="person" lay-filter="deptradio" tag="z0i" />
                                                                <input type="checkbox" lay-skin="primary" value="3917324" title="韩斌" name="person" lay-filter="deptradio" tag="z0i" />
                                                            </div>
                                                            <div class="layui-tab-item layui-form  layui-show">
                                                                <div>第二组</div>
                                                                <input type="checkbox" lay-skin="primary" value="" title="全选" name="person" lay-filter="deptradio" id="z1" />
                                                                <input type="checkbox" lay-skin="primary" value="000" title="000" name="person" lay-filter="deptradio" tag="z1i" />
                                                                <input type="checkbox" lay-skin="primary" value="111" title="111" name="person" lay-filter="deptradio" tag="z1i" />
                                                                <input type="checkbox" lay-skin="primary" value="222" title="222" name="person" lay-filter="deptradio" tag="z1i" />
                                                            </div>-->
                                                        </div>

                                                    </div>
                                                    <!--<div class="layui-tab lay-ele-row2" id="persontabSearch" style="display:none;">
                                                        <div class="layui-form-item layui-search">
                                                            <input type="text" placeholder="输入姓名搜索" id="searchName" class="layui-input" />
                                                            <button type="button" class="layui-btn layui-btn-primary" id="findperson" name="查询"><i class="layui-icon"></i>查询</button>
                                                            <div class="layui-input-inline" id="PersonContent1">

                                                            </div>
                                                        </div>
                                                    </div>-->
                                                </div>

                                            </div>

                                        </div>

                                    </div>
                                </div>

                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">课程内容</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-form layui-form-pane">
                                            <div class="layui-form-item">

                                            </div>
                                            <button type="button" class="layui-btn layui-btn-normal" id="insertContent1">新增</button>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-colla-item">
                                    <h2 class="layui-colla-title">每周两题</h2>
                                    <div class="layui-colla-content layui-show">
                                        <div class="layui-form layui-form-pane">
                                            <div class="layui-form-item">

                                            </div>
                                            <button type="button" class="layui-btn layui-btn-normal" id="insertContent2">新增</button>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var ModleNameTip = "培训课程";  //模块名称  用于提示部门信息的内容
        var contollerName = "TrainCourse";
        var tempSearchPersonList = [];//
        var load = 1;
        var CPID = 0;
        var refTPID = 0;
        var prePlanId = 0;
        var selectIDs = [];
        var selectCurrentID = 0;
        var currentDeptLevelId = 0;//当前登录者 部门级别  0：是段
        var currentInfoDeptLevelId = 0;//当前选中信息的  部门级别  [用于判断 是否能够对 该条信息进行修改:下级不能对上级的计划信息进行修改]
        var cuurentDeptId = 0;//当前部门id
        var selectCurrentIsCheckStatus = 0;// 当前选中的行的 IsChck 状态  [用于删除/审核/取消审核/发布/取消发布时判断]
        var selectCurrentIsReleaseStatus = 0;// 当前选中的行的 IsRelease 状态  [用于删除/审核/取消审核/发布/取消发布时判断]
        var currentInfoDeptId = 0;
        var selectobjs = [];
        var FileListIds = [];
        var img = ApiUrl.replace("api", "");
        var teacherList = [];
        var classRoom = [];
        var vList1 = [];
        var vList2 = [];
        var dis1 = "fr_";
        var dis2 = "sr_";
        var v1max = 0;
        var v2max = 0;
        var dataSelect = [];
        var dataSelect2 = [];
        var temp_deptId_List = [];
        var temp_deptId_List2 = [];
        var dataCurent = [];
        var th = 0;
        var tw = 0;
        var personName = [];//当前选择的用户名
        function SelectGroupTF(v) {
            layui.use(['layer', 'jquery'], function () {
                var h = th * 1.6;
                var w = tw * 0.8;
                var layer = layui.layer;
                var $ = layui.jquery;
                var contentPage = "../traincontent/file_SelectList.html";
                var title = "选择培训资料";
                layer.open({
                    title: title,
                    type: 2,
                    area: [w + "px", h + "px"],
                    btn: ['确定'],
                    content: contentPage,
                    yes: function (index) {
                        var res = window["layui-layer-iframe" + index].selectdata();
                        var SelectFileObjList = res.objList;
                        var TempFileNames = [];
                        FileListIds = [];
                        var files = [];
                        for (var i = 0; i < SelectFileObjList.length; i++) {
                            var item = SelectFileObjList[i];
                            TempFileNames.push(item.TFName);
                            files.push({ id: item.TFID, name: item.TFName });
                        }
                        var vs = $(v).parent().parent().attr("id").split("_");
                        if (vs[0] == dis1.split("_")[0]) {
                            for (var i = 0; i < vList1.length; i++) {
                                var item = vList1[i];
                                if (vList1[i].idx == vs[1]) {
                                    vList1.splice(i, 1);
                                    vList1.push({ idx: item.idx, CName: item.CName, files: files });
                                    break;
                                }
                            }
                        }
                        else {
                            for (var i = 0; i < vList2.length; i++) {
                                var item = vList2[i];
                                if (vList2[i].idx == vs[1]) {
                                    vList2.splice(i, 1);
                                    vList2.push({ idx: item.idx, CName: item.CName, files: files });
                                    break;
                                }
                            }
                        }

                        files = [];
                        $(v).val(TempFileNames.toString());
                        layer.close(index);
                    }
                });
            });
        }
        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer', 'tree', 'util'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            th = $(document).height() * 0.5;
            tw = $(document).width();
            var table = layui.table;
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            var eleTree = layui.tree;
            var eleTree2 = layui.tree;
            $(function ($) { $.fn.layuiTextArea = function (options) { var defaults = { maxHeight: null, minHeight: $(this).height() }; var opts = $.extend({}, defaults, options); return $(this).each(function () { $(this).bind("paste cut keydown keyup focus blur", function () { var height, style = this.style; this.style.height = opts.minHeight + 'px'; if (this.scrollHeight > opts.minHeight) { if (opts.maxHeight && this.scrollHeight > opts.maxHeight) { height = opts.maxHeight; style.overflowY = 'scroll'; } else { height = this.scrollHeight; style.overflowY = 'hidden'; } style.height = height + 'px'; } }); }); }; });
            $(".layui-card-header").find("button").each(function () { if (PowerList.indexOf($(this).attr("name")) <= -1) { $(this).attr("style", "display:none;") } });
            form.on('switch(switch)', function (data) { });
            function DateMeth(time1, time2) {
                if (time1 != "" && time2 != "") {
                    if (time1 > time2) {
                        return false;
                    }
                    var begin1 = time1.substr(0, 10).split("-"); var end1 = time2.substr(0, 10).split("-"); var date1 = new Date(begin1[0] + "-" + begin1[1] + "-" + begin1[2]); var date2 = new Date(end1[0] + "-" + end1[1] + "-" + end1[2]); var m = parseInt(Math.abs(date2 - date1) / 1000 / 60); var min1 = parseInt(time1.substr(11, 2)) * 60 + parseInt(time1.substr(14, 2)); var min2 = parseInt(time2.substr(11, 2)) * 60 + parseInt(time2.substr(14, 2)); var n = min2 - min1; var minutes = m + n; $("#Duration").val(minutes);
                }
            }
            laydate.render({
                elem: '#StartDateTime', trigger: 'click', type: 'date'
                , done: function (value, date, endDate) {
                    var c = value.substr(0, 10) + " " + $("#start").val();
                    var end = $("#EndDateTime").val() + " " + $("#end").val();
                    DateMeth($("#EndDateTime").val() + " " + $("#start").val(), end);
                }
            });
            laydate.render({
                elem: '#EndDateTime', trigger: 'click', type: 'date'
                , done: function (value, date, endDate) {
                    var start = $("#StartDateTime").val() + " " + $("#start").val();
                    var c = value.substr(0, 10) + " " + $("#end").val();
                    DateMeth(start, $("#StartDateTime").val() + " " + $("#end").val());
                }
            });
            laydate.render({
                elem: '#start'
                , type: 'time'
                , format: 'HH:mm'
                , trigger: 'click'
                , done: function (value, date, endDate) {
                    var start = $("#StartDateTime").val() + " " + value;
                    DateMeth(start, $("#StartDateTime").val() + " " + $("#end").val());
                }
            });
            laydate.render({
                elem: '#end'
                , type: 'time'
                , format: 'HH:mm'
                , trigger: 'click'
                , done: function (value, date, endDate) {
                    var end = $("#StartDateTime").val() + " " + value;
                    DateMeth($("#StartDateTime").val() + " " + $("#start").val(), end);
                }
            });
            $("input[name=time]").bind("input propertychange change", function (event) {
                DateMeth($("#StartDateTime").val() + " " + $("#start").val(), $("#StartDateTime").val() + " " + $("#end").val());
            });
            function PageInit() {
                var obj = $("div[lay-id='dataList']");
                var child = $(".layui-table-body");
                var off = obj.offset().top;
                var c = th - off - 100;
                child.attr("style", "height:" + c + "px");
            }
            element.on('collapse(infos_form)', function (data) {
                PageInit();
            });
            function InitItem() {
                $("button[name='delitems']").off("click").on("click", function () { DelItems($(this).parent()); }); $("textarea[name='ZName']").off("click").on("click", function () { SelectGroupTF($(this)); }); $("textarea").layuiTextArea({ maxHeight: 500, })
            }
            function formRenderSelect() {
                form.render('select');
            }
            function formRenderCk() {
                form.render('checkbox');
            }
            $("#insertContent1").on("click", function () {
                p1();
            });
            $("#insertContent2").on("click", function () {
                p2();
            });
            $("#PrePlanName").bind("click", function () {
                var h = th * 1.5;
                var w = tw * 0.8;
                var layer = layui.layer;
                var $ = layui.jquery;
                contentPage = "../plan/trainplan_SelectList.html?plan=1";
                title = "选择上级培训计划";
                layer.open({
                    title: title,
                    type: 2,
                    area: [w + "px", h + "px"],
                    btn: ['确定'],
                    content: contentPage,
                    yes: function (index) {
                        var res = window["layui-layer-iframe" + index].selectdata();
                        $("#PrePlanName").val(res.RefName); prePlanId = res.RefID;
                        $.ajax({
                            url: ApiUrl + "TrainPlan/GetContent?TPID=" + res.RefID,
                            type: 'get',
                            headers: {
                                "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                            },
                            success: function (data, res) {
                                empty();
                                if (data.StatusCode == 200) {
                                    vList1 = data.Data.vList1;
                                    vList2 = data.Data.vList2;
                                    MathList();
                                }
                                else if (data.StatusCode == 403) {
                                    layer.alert(data.Info, function () {
                                        top.location.href = "http://" + top.location.host + "/login.html";
                                    })
                                }
                                else {
                                    if (data.Info != null) {
                                        layer.msg(data.Info);
                                    }
                                }
                            }
                        });
                        $("#download").empty();
                        if (res.AnnexUrl != undefined && res.AnnexName != undefined && res.AnnexUrl != null && res.AnnexName != null && res.AnnexUrl != "" && res.AnnexName != null) { $("#download").append("<a href=\"" + img + res.AnnexUrl + "\" style=\"color: blue\" download=\"" + img + res.AnnexName + "\">附件:" + res.AnnexName + "</a>"); }

                        layer.close(index);
                    }
                });
            });
            function p1() {
                vList1.push({ idx: v1max, CName: "", files: [{ id: 0, name: "" }] });
                SetItems($("#insertContent1"), dis1, v1max); v1max++;
            }
            function p2() {
                vList2.push({ idx: v2max, CName: "", files: [{ id: 0, name: "" }] });
                SetItems($("#insertContent2"), dis2, v2max); v2max++;
            }
            function SetItemsValue(obj, cv, zv, tv) {
                $("#" + obj).find("textarea[name=CName]").val(cv);
                $("#" + obj).find("textarea[name=ZName]").val(zv);
                $("#" + obj).find("input[name=TCDuration]").val(tv);
                $("#" + obj).find("textarea[name=CName]").click();
            }
            function ClearItems(obj) {
                obj.parent().find(".layui-form-item").find(".layui-row").remove();
            }
            function SetItems(obj, dis, index) {
                var c = obj.parent().find(".layui-form-item");
                var v = "<div class=\"layui-row\" id=\"" + dis + index + "\">";
                v += "<div class=\"layui-input-md2 layui-input-row\">";// class=\"layui-textarea\"   style=\"resize:none;\"  rows=\"10\"
                v += " <textarea    placeholder=\"内容\" class=\"layui-textarea\"   name=\"CName\" ></textarea>";
                v += "</div>";
                v += "<div class=\"layui-input-md1 layui-input-row\">";
                v += " <textarea   placeholder=\"选择资料\" class=\"layui-textarea\"    name=\"ZName\" ></textarea>";
                v += "</div>";
                v += "<div class=\"layui-input-md3 layui-input-row\">";
                v += "<input type=\"text\" placeholder=\"学时\" maxlength=\"50\" class=\"layui-input layui-input-full\" name=\"TCDuration\"  />";
                v += "</div>";
                v += "<button type=\"button\" class=\"layui-btn layui-btn-danger\"  name=\"delitems\" >删除</button>";
                v += "</div>";
                c.append(v);
                InitItem();
            }
            function GetItems(obj, vlist) {
                var resultList = [];
                obj.parent().find(".layui-form-item").find(".layui-row").each(function () {
                    var vlistx = $(this).attr("id").split("_")[1];
                    for (var i = 0; i < vlist.length; i++) {
                        if (vlist[i].idx == vlistx) {
                            resultList.push({ idx: vlistx, CName: $(this).find("textarea[name=CName]:first").val(), files: vlist[i].files, TCDuration: $(this).find("input[name=TCDuration]:first").val() });
                        }
                    }
                });
                return resultList;
            }
            function DelItems(bobj) {
                var vs = $(bobj).attr("id").split("_");
                if (vs[0] == dis1.split("_")[0]) {
                    for (var i = 0; i < vList1.length; i++) {
                        if (vList1[i].idx == vs[1]) {
                            vList1.splice(i, 1);
                            $(bobj).remove();
                            break;
                        }
                    }
                }
                else {
                    for (var i = 0; i < vList2.length; i++) {
                        if (vList2[i].idx == vs[1]) {
                            vList2.splice(i, 1);
                            $(bobj).remove();
                            break;
                        }
                    }
                }
            }
            function empty() {
                ClearItems($("#insertContent1"));
                ClearItems($("#insertContent2"));
                vList1 = []; vList2 = []; v1max = 0; v2max = 0;
            }
            function MathList() {
                for (var i = 0; i < vList1.length; i++) {
                    var item = vList1[i];
                    SetItems($("#insertContent1"), dis1, v1max);
                    SetItemsValue(dis1 + v1max, item.CName, item.files.map(function (v) { return v.name; }).toString(), item.TCDuration);
                    v1max++;
                }
                for (var i = 0; i < vList2.length; i++) {
                    var item = vList2[i];
                    SetItems($("#insertContent2"), dis2, v2max);
                    SetItemsValue(dis2 + v2max, item.CName, item.files.map(function (v) { return v.name; }).toString(), item.TCDuration);
                    v2max++;
                }
            }
            $(function () {
                p1(); p2(); InitItem();
            });
            function GetRoom(DeptID) {
                $.ajax({
                    url: ApiUrl + "TrainClassRoom/Sel",
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { '': JSON.stringify(DeptID) },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            if (data.Data != "") {
                                for (var i = 0; i < data.Data.length; i++) {
                                    var item = data.Data[i];
                                    classRoom.push({ id: item.CRID, name: item.CRName });
                                }
                                GetSelectList(classRoom, $("#CRName"), formRenderSelect);
                                SetselectValue($("#CRName"), data.Data[0].CRID, formRenderSelect);
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            function GetTeacher(DeptID) {
                $.ajax({
                    url: ApiUrl + "TrainTeacher/Sel",//SelTree
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { '': JSON.stringify(DeptID) },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            if (data.Data != "") {
                                for (var i = 0; i < data.Data.length; i++) {
                                    var item = data.Data[i];
                                    teacherList.push({ id: item.TeacherID, name: item.TeacherName });
                                }
                                GetSelectList(teacherList, $("#TrainTeacherName"), formRenderSelect);
                                SetselectValue($("#TrainTeacherName"), data.Data[0].TeacherID, formRenderSelect);
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            $.ajax({
                url: ApiUrl + "Dep/DeptLevel",//SelTree
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        currentDeptLevelId = data.Data.currentDeptLevelId;
                        cuurentDeptId = data.Data.cuurentDeptId;
                        GetDept(cuurentDeptId);
                        GetUserInfo(cuurentDeptId);
                        GetRoom(cuurentDeptId);
                        GetTeacher(cuurentDeptId);
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            top.location.href = "http://" + top.location.host + "/login.html";
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
            function GetSingleCourseContent(TCOID) {
                $.ajax({
                    url: ApiUrl + "TrainCourse/GetContent?TCOID=" + TCOID,
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        empty();
                        if (data.StatusCode == 200) {
                            vList1 = data.Data.vList1;
                            vList2 = data.Data.vList2;
                            MathList();
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            if (data.Info != null) {
                                layer.msg(data.Info);
                            }
                        }
                    }
                });
            }
            function GetDept(deptid) {
                var r = 0;
                $.ajax({
                    url: ApiUrl + "Dep/SelNextTree",//SelTree
                    type: 'post',
                    async: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { DepID: deptid },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            dataSelect = data.Data;
                            loadTree();
                            r = 1;
                            if (dataSelect.length <= 0) {
                                $("#selectDeptShow").attr("style", "display:none;");
                            }
                            else {
                                $("#selectDeptShow").attr("style", "display:block;");
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return r;
            }
            function GetUserInfo(deptid) {
                var r = 0;
                $.ajax({
                    url: ApiUrl + "UserInfo/SelNextTree",//SelTree
                    type: 'post',
                    async: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { DepIDs: deptid },
                    success: function (data) {
                        //alert("1111")

                        if (data.StatusCode == 200) {
                            dataSelect2 = data.Data;

                            Ctitle();
                            
                            r = 1;
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return r;
            }
            function SelectAll(data, flag) {
                $("input[type=checkbox][name=person][tag=" + data.elem.id + "i]").each(function () {
                    if (flag) {
                        if (!$(this).prop("checked")) {
                            temp_deptId_List2.push($(this).context.value);
                            personName.push($(this).context.title);
                        }
                    }
                    else {
                        if ($(this).prop("checked")) {
                            temp_deptId_List2.splice(temp_deptId_List2.indexOf($(this).context.value), 1);
                            personName.splice(personName.indexOf($(this).context.title), 1);
                        }
                    }
                    $(this).prop("checked", flag);
                });
                formRenderCk();
            }
            form.on('checkbox(deptradio)', function (data) {
                if (data.elem.value == "") {
                    SelectAll(data, data.elem.checked);
                }
                else {
                    if (data.elem.checked) {
                        temp_deptId_List2.push(data.value);
                        personName.push(data.elem.title);
                    }
                    else {
                        temp_deptId_List2.splice(temp_deptId_List2.indexOf(data.value), 1);
                        personName.splice(personName.indexOf(data.elem.title), 1);
                    }
                }

                $("#selectDatas2").val(personName.toString());
            });
            function clearPerson() {
                //$("#Persontitle").find("li").remove();
                //$("#PersonContent").find(".layui-tab-item").remove();
                $("#AllPerson").find("span").remove();
                $("#AllPerson").find(".layui-tab-item").remove();

            }
            function Ctitle() {
                //console.log(dataSelect2)
                clearPerson();
                //for (var i = 0; i < dataSelect2.length; i++) {
                //    var item = dataSelect2[i];
                //    var a = ""; var kc = "";
                //    if (i == 0) { a = "<li class=\"layui-this\">" + item.title + "</li>"; kc = "<div class=\"layui-tab-item layui-form layui-show\">"; }
                //    else { a = "<li class=\"\">" + item.title + "</li>"; kc = "<div class=\"layui-tab-item layui-form\">"; }
                //    $("#Persontitle").append(a);
                //    if (item.children != undefined) {
                //        for (var k = 0; k < item.children.length; k++) {
                //            var ic = item.children[k];
                //            if (k == 0) {
                //                kc += "<input type=\"checkbox\" lay-skin=\"primary\"  value=\"\" title=\"全选\" name=\"person\"  lay-filter=\"deptradio\" id=\"z" + i + "\"/ />";
                //            }
                //            kc += "<input type=\"checkbox\" lay-skin=\"primary\"  value=\"" + ic.id + "\" title=\"" + ic.title + "\" name=\"person\" lay-filter=\"deptradio\" tag=\"z" + i + "i\" />";

                //        }
                //        kc += "</div>";
                //        //alert(kc)
                //        $("#PersonContent").append(kc);
                //    }
                //}
                
                for (var i = 0; i < dataSelect2.length; i++) {
                    var ap = "";
                    item = dataSelect2[i];
                    //alert(item.title)
                    ap += "<div><span>" + item.title + "<span></div>";
                    ap += "<div class=\"layui-tab-item layui-form layui-show\">";
                    ap += "<input type=\"checkbox\" lay-skin=\"primary\" value=\"\" title=\"全选\" name=\"person\" lay-filter=\"deptradio\" id=\"z" + i + "\" />";
                    if (item.children != undefined) {
                        for (var k = 0; k < item.children.length; k++) {
                            var ic = item.children[k];
                            ap += "<input type=\"checkbox\" lay-skin=\"primary\"  value=\"" + ic.id + "\" title=\"" + ic.title + "\" name=\"person\" lay-filter=\"deptradio\" tag=\"z" + i + "i\" />";
                        }
                        ap += "</div>"
                        $("#AllPerson").append(ap);
                    }
                }
               
                formRenderCk();
            }
            function SetChecked(temp_deptId_List_2) {
                personName = [];
                $("input[name=person]").each(function () {
                    var v = this.value;
                    if (temp_deptId_List_2.indexOf(v) > -1) {
                        this.checked = true;
                        personName.push(this.title);
                    }
                });
                formRenderCk();
                $("#selectDatas2").val(personName.toString());
            }
            var tempList = [];
            function SetTextFromTree(v) {
                for (var i = 0; i < v.length; i++) {
                    var c = v[i];
                    tempList.push({ id: c.id, title: c.title });
                    temp_deptId_List.push(c.id);
                    var a = $("#selectDatas").val();
                    if (a != "") { a += ","; }
                    $("#selectDatas").val(a + c.title);
                    if (c.children != undefined) {
                        if (c.children.length > 0) {
                            SetTextFromTree(c.children);
                        }
                    }
                }
            }
            function setTree()//选择信息列表中 信息时 调用该方法  并为temp_deptId_List赋值
            {
                eleTree.setChecked('eleTreeid', temp_deptId_List);
            }
            var el_tree;
            $("#selectDatas").on("click", function (e) {
                e.stopPropagation();
                loadTree();
                $(".eleTree").toggle();
            });
            $("#selectDatas2").on("click", function (e) {
                $("#persontab").toggle(function () { $(this).click(function () { $("#persontab").hide(); }); }, function () { $(this).click(function () { $("#persontab").show(); }); });
                $("#persontabSearch").toggle(function () { $(this).click(function () { $("#persontabSearch").hide(); }); }, function () { $(this).click(function () { $("#persontabSearch").show(); }); });
            });
            function loadTree() {
                el_tree =
                    eleTree.render({
                        elem: '.eleTree',
                        id: 'eleTreeid',
                        data: dataSelect,
                        defaultExpandAll: false,
                        expandOnClickNode: false,
                        highlightCurrent: true
                        , checkStrictly: true
                        , showCheckbox: true
                        , oncheck: function (obj) {
                            $("#selectDatas").val("");
                            temp_deptId_List = [];
                            tempList = [];
                            SetTextFromTree(el_tree.getChecked());
                        }
                    });
            }
            function showList() {
                var swhere = JSON.stringify({
                    StartDateTime: $("#StartDateTime").val(),
                    EndDateTime: $("#EndDateTime").val(),
                    //IsRelease: $("#IsRelease").val(),
                    IsUse: 1,
                    self: 0
                });
                table.render({
                    elem: '#dataList'
                    , url: ApiUrl + contollerName + '/Search'
                    , id: "dataList"
                    , headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    }
                    , page: true
                    , cols: [[
                        { type: 'checkbox' },
                        { field: 'AutoID', title: 'AutoID', sort: true, hide: true },
                        { field: 'TPID', title: '计划id', sort: true, hide: true },
                        { field: 'TCID', title: '授课内容id', sort: true, hide: true },
                        { field: 'TCOID', title: '编号', sort: true, hide: true },
                        { field: 'CRID', title: '教室编号', sort: true, hide: true },
                        { field: 'TCOName', title: '课程名称', width: 300 },
                        { field: 'CRName', title: '教室', width: 150 },
                        { field: 'TrainTeacherID', title: '培训教师ID', hide: true },
                        { field: 'TrainTeacherName', title: '培训教师', width: 150 },
                        { field: 'Duration', title: '时长(分钟)', width: 100 },
                        {
                            field: 'StartDateTime', title: '开始时间', width: 150, templet: function (d) {
                                if (d.StartDateTime != undefined) {
                                    return d.StartDateTime.substring(0, 16).replace("T", " ");
                                }
                                else {
                                    return "";
                                }
                            },
                        },
                        {
                            field: 'EndDateTime', title: '结束时间', width: 150, templet: function (d) {
                                if (d.EndDateTime != undefined) {
                                    return d.EndDateTime.substring(0, 16).replace("T", " ");
                                }
                                else {
                                    return "";
                                }

                            },
                        },
                        { field: 'DepID', title: '部门id', hide: true },
                        { field: 'DepLevel', title: '部门级别id', hide: true },
                        { field: 'AddUserID', title: '添加人员id', hide: true },
                        { field: 'AddUserName', title: '添加人员姓名',width: 100, },
                        {
                            field: 'AddDateTime', title: '添加时间', width: 120, templet: function (d) {
                                if (d.AddDateTime != undefined) {
                                    return d.AddDateTime.substring(0, 10);
                                }
                                else {
                                    return "";
                                }
                            },
                        },
                        { field: 'SendDepID', title: '下发部门id', hide: true },
                        {
                            field: 'IsCheck', title: '审核', width: 100, templet: function (d) {
                                return d.IsCheck == "0" ? "未审核" : "已审核";
                            }
                        },

                        //{ field: 'IsUse', title: '使用状态', width: 100, templet: function (d) { return d.IsUse == "0" ? "未用" : "在用" } }
                    ]]
                    , where: { swhere: swhere }
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    event: true,
                    page: true,
                    done: function (res, curr, count) {
                        //如果是异步请求数据方式，res即为你接口返回的信息。
                        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                        if (res.data != null) {
                            var p = $(".layui-laypage-skip").find("input[type=text]").val();
                            var c = $(".layui-laypage-limits select").find("option:selected").text().substring(0, 2);
                            var k = (Number(p) - 1) * Number(c);
                            for (var i = 0; i < res.data.length; i++) {
                                var item = res.data[i];
                                var ix = item.Row - 1 - k;
                            }
                        }

                        if (res.code == 403) {
                            layer.alert(res.msg, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                    }
                });
            }
            showList();
            function defaults() {
                $("#start").val("09:00"); $("#end").val("10:30");
                var c = new Date(); var f = new Date();
                f.setDate(f.getDate() + 7);
                var star = getdates(c);
                var end = getdates(f);
                $("#StartDateTime").val(star);
                $("#EndDateTime").val(end);
                $("#Duration").val(90);
            }
            function getdates(v, v1) {
                var year = v.getFullYear();
                var month = v.getMonth() + 1;
                var day = v.getDate();
                if (month < 10) { month = "0" + month; }
                if (day < 10) { day = "0" + day; }
                var hh = 9;
                var mm = 0;
                var date = year + "-" + month + "-" + day;
                return date;
            }
            $(function () {
                $("del").hide();
                $("#sreach").click(function () {
                    showList();
                });
                defaults();
            })
            PageInit();
            function clearForm() {
                $("textarea").val("");
                $("input").val("");
                $("#IsRelease").val("");
                $("#download").empty();
                empty();
                temp_deptId_List2 = [];
                personName = [];
                //$("#EndDateTime").val();
            }
            function GerCourseFiles(TCOID) {
                var courseFileWhere = JSON.stringify({ TCOID: TCOID });
                $.ajax({
                    url: ApiUrl + "TrainCourseFiles/Search",//SelTree
                    type: 'post',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { '': courseFileWhere },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            FileListIds = [];
                            var tempFileNames = [];
                            if (data.Data != null) {
                                for (var i = 0; i < data.Data.length; i++) {
                                    var item = data.Data[i];
                                    FileListIds.push(item.TFID);
                                    tempFileNames.push(item.TFName);
                                }
                                $("#PreTFName").val(tempFileNames.toString());
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            function GetSinglePrePlanOrCorp(TPID) {
                //选择上级计划
                $.ajax({
                    url: ApiUrl + "TrainPlan/GetSingle?TPID=" + TPID,
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            $("#PrePlanName").val(data.Data.TPName);

                            $("#download").empty();
                            if (data.Data.AnnexUrl != undefined && data.Data.AnnexName != undefined && data.Data.AnnexUrl != null && data.Data.AnnexName != null && data.Data.AnnexUrl != "" && data.Data.AnnexName != null) { $("#download").append("<a href=\"" + img + data.Data.AnnexUrl + "\" style=\"color: blue\" download=\"" + img + data.Data.AnnexName + "\">附件:" + data.Data.AnnexName + "</a>"); }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            function GetUserListByCourAndDeptId(data) {
                var depid = 0;
                if (currentDeptLevelId > currentInfoDeptLevelId) {
                    depid = cuurentDeptId;
                    tempdep = cuurentDeptId;
                }
                else if (currentDeptLevelId <= currentInfoDeptLevelId) {
                    depid = currentInfoDeptId;
                    var tempdep = data.SendDepID;
                }
                var apiUrl = "TrainCourseUser/GetCourseUserListByCourseIdAndDeptId?TCOID=" + data.TCOID + "&DetpId=" + tempdep + "";
                $.ajax({
                    url: ApiUrl + apiUrl,
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            temp_deptId_List2 = [];
                            personName = [];
                            if (data.Data != null) {
                                for (var i = 0; i < data.Data.length; i++) {
                                    temp_deptId_List2.push(data.Data[i].UserID.toString());
                                }
                            }
                            GetUserInfo(tempdep);
                            SetChecked(temp_deptId_List2);
                            //setTree2();
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            function GetSingleInfo(data) {
                $("#selectDatas2").val("");
                temp_deptId_List = [];
                temp_deptId_List2 = [];
                // GerCourseFiles(data.TCOID);
                if (data.TPID != null) {
                    prePlanId = data.TPID;
                    GetSinglePrePlanOrCorp(prePlanId);
                }
                GetSingleCourseContent(data.TCOID);
                var star = data.StartDateTime.substring(0, data.StartDateTime.length - 3).split('T');
                var end = data.EndDateTime.substring(0, data.EndDateTime.length - 3).split('T');
                $("#StartDateTime").val(star[0]);
                $("#start").val(star[1]);
                $("#EndDateTime").val(end[0]);
                $("#end").val(end[1]);
                $("#IsRelease").val(data.IsRelease);

                $("#TCOName").val(data.TCOName);
                SetselectValue($("#TrainTeacherName"), data.TrainTeacherID, formRenderSelect);
                SetselectValue($("#CRName"), data.CRID, formRenderSelect);
                var dur = 0;
                if (data.Duration != null && data.Duration != "") {
                    dur = data.Duration;
                }
                $("#Duration").val(dur);
                refTPID = data.TPID;
                currentInfoDeptLevelId = data.DepLevel;
                currentInfoDeptId = data.DepID;
                var r = GetDept(currentInfoDeptId);
                if (r == 1) {
                    if (data.SendDepID != null) {
                        if (data.SendDepID.indexOf(',') > -1) {
                            var tpids = data.SendDepID.split(',');
                            for (var i = 0; i < tpids.length; i++) {
                                temp_deptId_List.push(Number(tpids[i]));
                            }
                        }
                        else {
                            temp_deptId_List.push(Number(data.SendDepID));
                        }
                        setTree();
                    }
                }
                GetUserListByCourAndDeptId(data);
                //add by cjh
                selectCurrentIsCheckStatus = data.IsCheck;
                selectCurrentIsReleaseStatus = data.IsRelease;
            }
            ///按钮操作 开始
            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(dataList)', function (obj) {
                var checked = false;
                var objcheck = $(obj.tr.selector).find("td").eq(0).find(".layui-table-cell").eq(0).find("div").eq(0);
                if (selectIDs.indexOf(obj.data.TCOID) > -1) {
                    $(obj.tr.selector).find("td").eq(0).find(".layui-table-cell").eq(0).find("input[type=checkbox]").prop("checked", false)
                }
                else {
                    checked = true;
                    $(obj.tr.selector).find("td").eq(0).find(".layui-table-cell").eq(0).find("input[type=checkbox]").prop("checked", true)
                }
                if (checked) {
                    if (obj.data.TCOID != undefined) {
                        selectCurrentID = obj.data.TCOID;
                        selectIDs.push(obj.data.TCOID);
                        selectobjs.push(obj.data);
                        GetSingleInfo(obj.data);
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TCOID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TCOID;
                            }
                        }
                    }
                }
                else {
                    if (obj.data.TCOID != undefined) {
                        selectIDs.splice(selectIDs.indexOf(obj.data.TCOID), 1);
                        for (var i = 0; i < selectobjs.length; i++) {
                            if (selectobjs[i].TCOID == obj.data.TCOID) {
                                if (i == selectobjs.length - 1) {
                                    selectCurrentID = 0;
                                    selectCurrentName = "";
                                    if (i > 0) {
                                        if (selectobjs[i - 1].TCOID != undefined) {
                                            selectCurrentID = selectobjs[i - 1].TCOID;
                                            GetSingleInfo(selectobjs[i - 1]);
                                        }
                                    }
                                    else {
                                        clearForm(); selectCurrentID = 0;
                                    }
                                }
                                selectobjs.splice(i, 1);
                                break;
                            }
                        }
                        if (selectIDs <= 0) {
                            temp_deptId_List = [];
                            temp_deptId_List2 = [];
                            var r = GetDept(cuurentDeptId);
                            if (r == 1) {
                                setTree();
                            }
                            var r2 = GetUserInfo(cuurentDeptId);
                            if (r2 == 1) {
                                //setTree2();
                            }
                        }
                    }
                    else {
                        clearForm();
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        temp_deptId_List = [];
                        var r = GetDept(cuurentDeptId);
                        if (r == 1) {
                            setTree();
                        }
                        temp_deptId_List2 = [];
                        var r2 = GetUserInfo(cuurentDeptId);
                        if (r2 == 1) {
                            //setTree2();
                        }
                    }
                }
            });
            table.on('checkbox(dataList)', function (obj) {
                if (obj.data.AutoID == undefined) {
                    selectIDs = [];
                    selectCurrentID = 0;
                    selectobjs = [];
                    if (obj.checked) {
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TCOID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TCOID;
                            }
                        }
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        clearForm();
                        temp_deptId_List = [];
                        var r = GetDept(cuurentDeptId);
                        if (r == 1) {
                            setTree();
                        }
                        temp_deptId_List2 = [];
                        var r2 = GetUserInfo(cuurentDeptId);
                        if (r2 == 1) {
                            //setTree2();
                        }
                    }
                }
            });
            $("#find").click(function () {
                showList();
            });
            $("#reset").click(function () {
                reset();
            });
            $("#download").click(function () {
                var annex = $("#download")[0].textContent;
                if (annex == "") return;
                var filename = annex.split(':')[1];
                console.log(filename);


                $.ajax({
                    url: ApiUrl + "TrainFileDownLog/Add2",
                    type: 'get',
                    //dataType: 'json',
                    cache: false,
                    data: {
                        filename: filename
                    },
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        console.log("下载成功！");
                    }
                });
            });

            function reset() {
                clearForm();
                temp_deptId_List = [];
                temp_deptId_List2 = [];
                selectCurrentID = 0;
                GetDept(cuurentDeptId);
                GetUserInfo(cuurentDeptId);
                setTree();
            }
            function CheckData() {
                if (prePlanId <= 0) {
                    layer.msg("请选择计划！");
                    return false;
                }
                if ($("#StartDateTime").val().trim() == "") {
                    layer.msg("请选择开始时间！");
                    return false;
                }
                if ($("#EndDateTime").val().trim() == "") {
                    layer.msg("请选择结束时间！");
                    return false;
                }
                if ($("#Duration").val().trim() == "") {
                    layer.msg("请输入时长(分钟)！");
                    return false;
                }
                return true;
            }
            function GetFormData() {
                //FileListIds   文件资料id 数组值
                var TPName = $("#TPName").val();//计划名称
                var ID = CPID;//prePlanId;//集团id
                //var TCID = prePlanId;// prePlanId;//上级计划id
                var StartDateTime = $("#StartDateTime").val() + " " + $("#start").val();
                var EndDateTime = $("#EndDateTime").val() + " " + $("#end").val();
                console.log(StartDateTime);
                console.log(EndDateTime);
                var Duration = $("#Duration").val();
                var RoomName = $("#CRName option:selected").text();
                var RoomId = $("#CRName").val();
                var TeacherName = $("#TrainTeacherName option:selected").text();
                var TeacherId = $("#TrainTeacherName").val();
                var TCOName = $("#TCOName").val();
                return model = {
                    TCOName: TCOName,
                    TPName: TPName,
                    TPID: prePlanId,//refTPID,
                    TCID: 0,
                    StartDateTime: StartDateTime,
                    EndDateTime: EndDateTime,
                    SendDepID: temp_deptId_List.toString(),
                    Duration: Duration,
                    TrainTeacherID: TeacherId,
                    TrainTeacherName: TeacherName,
                    CRID: RoomId,
                    CRName: RoomName,
                    IsRelease: false,
                    IsCheck: false,
                    IsUse: true
                }
            }
            function GetOperate(operRatetype, pcurrentInfoDeptLevelId) {
                //operRatetype:操作类型     pcurrentInfoDeptLevelId:当前需要操作的信息的  部门级别
                //operRatetype[1:修改，2：删除,3:审核,4:取消审核,5:发布 6:取消发布]
                var result = true;
                if (currentDeptLevelId > pcurrentInfoDeptLevelId) {
                    switch (operRatetype) {
                        case 1:
                            layer.msg("您没有权限，不能修改上级" + ModleNameTip + "");
                            result = false;
                            break;
                        case 2:
                            layer.msg("您没有权限，不能删除上级" + ModleNameTip + "");
                            result = false;
                            break;
                        case 3:
                            layer.msg("您没有审核权限，不能对该条信息进行审核");
                            result = false;
                            break;
                        case 4:
                            layer.msg("您没有取消审核权限，不能对该条信息进行取消审核");
                            result = false;
                            break;
                        case 5:
                            layer.msg("您没有发布信息权限，不能对该条信息进行发布");
                            result = false;
                            break;
                        case 6:
                            layer.msg("您没有取消发布权限，不能对该条信息进行取消发布");
                            result = false;
                            break;
                    }
                }
                return result;
            }
            function SynShow(data, selected) {
                var t = data.title;
                if (t.indexOf("(") > -1) {
                    t = t.substring(0, t.indexOf("("));
                }
                if (selected) {
                    if (temp_deptId_List2.indexOf(data.value) > -1) {
                    }
                    else {
                        temp_deptId_List2.push(data.value);
                        personName.push(t);
                    }
                }
                else {
                    temp_deptId_List2.splice(temp_deptId_List2.indexOf(data.value), 1);
                    personName.splice(personName.indexOf(t), 1);
                }
                $("input[type=checkbox][name=person][value=" + data.value + "]").each(function () {
                    $(this).prop("checked", selected);
                });
                formRenderCk();
                $("#selectDatas2").val(personName.toString());
            }
            form.on('checkbox(deptradio1)', function (data) {
                SynShow(data.elem, data.elem.checked);
            });
            function GetSelectPerson() {
                if (dataSelect2.length > 0) {
                    var searchName = $("#searchName").val();
                    if (searchName != "") {
                        tempSearchPersonList = [];
                        for (var i = 0; i < dataSelect2.length; i++) {
                            var item = dataSelect2[i];
                            for (var k = 0; k < item.children.length; k++) {
                                var kitem = item.children[k];
                                if (kitem.title.indexOf(searchName) > -1) {
                                    tempSearchPersonList.push(kitem);
                                }
                            }
                        }
                        CreateSearchPerson();
                    }
                    else {
                        layer.msg("姓名不能为空!"); return;
                    }
                }
            }
            tempSearchPersonList
            function CreateSearchPerson() {
                $("#PersonContent1").empty();
                if (tempSearchPersonList != undefined && tempSearchPersonList.length > 0) {
                    var kc = "";
                    for (var i = 0; i < tempSearchPersonList.length; i++) {
                        var item = tempSearchPersonList[i];
                        kc += "<input type=\"checkbox\" lay-skin=\"primary\" value=\"" + item.id + "\" title=\"" + item.title + "(" + item.id + ")\" name=\"person1\" lay-filter=\"deptradio1\" />";
                    }
                    $("#PersonContent1").append(kc);
                    //$("input[type=checkbox][name=person1]").each(function () { if (temp_deptId_List2.indexOf($(this).context.value) > -1) { $(this).prop("checked", true); } });
                    formRenderCk();
                }
            }
            $("#findperson").click(function () {
                GetSelectPerson();
            });
            //编辑保存
            form.on('submit(edit)', function (formdata) {
                if (selectCurrentID <= 0) {
                    add();
                }
                else {
                    edit();
                }
            });
            function add() {
                if (!CheckData()) { return; }
                var rList1 = GetItems($("#insertContent1"), vList1);
                var rList2 = GetItems($("#insertContent2"), vList2);
                if (rList1.length <= 0 && rList2.length <= 0) {
                    layer.msg("请输入课程内容/每周两课!"); return;
                }
                $.ajax({
                    url: ApiUrl + contollerName + "/AddList",
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    data: {
                        'vM_TrainCourse': GetFormData(), 'vList1': rList1
                        , 'vList2': rList2
                        , 'UserIds': temp_deptId_List2
                    },
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            layer.alert("添加保存成功", { icon: 6 }, function (index) {
                                layer.close(index); reset();
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Data);
                        }
                    }
                });
            }
            function edit() {
                if (!CheckData()) { return; }
                var model = GetFormData();
                var rList1 = GetItems($("#insertContent1"), vList1);
                var rList2 = GetItems($("#insertContent2"), vList2);
                if (rList1.length <= 0 && rList2.length <= 0) {
                    layer.msg("请输入课程内容/每周两题!"); return;
                }
                model.TCOID = selectCurrentID;
                //编辑保存 selectCurrentID
                $.ajax({
                    url: ApiUrl + contollerName + "/Edit",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        'vM_TrainCourse': model, 'vList1': rList1
                        , 'vList2': rList2
                        , 'UserIds': temp_deptId_List2
                    },
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {

                        if (data.StatusCode == 200 && data.Count != 0) {
                            layer.alert(data.Info, { icon: 6 }, function (index) {
                                layer.close(index); reset();
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            //删除
            $("#del").click(function () {

                if (!GetOperate(2, currentInfoDeptLevelId)) { return; }
                if (selectIDs.length == 0) {
                    layer.msg("请选择要删除的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == 1) {
                    layer.msg("已审核的" + ModleNameTip + "不能删除！");
                    return;
                }
                if (selectCurrentIsReleaseStatus == 1) {
                    layer.msg("已发布的" + ModleNameTip + "不能删除！");
                    return;
                }
                layer.confirm('确定要删除吗,已审核或发布的将不会执行删除?', function (index) {
                    var delList = '';
                    for (var i = 0; i < selectIDs.length; i++) {
                        delList += selectIDs[i] + ',';
                    }

                    delList = delList.substring(0, delList.length - 1);

                    $.ajax({
                        url: ApiUrl + contollerName + "/DelList",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { delidlist: delList },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert("删除成功", { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });


                    //删除 selectIDs
                    layer.close(index);
                });
            });
            function showpreview() {
                layui.use(['layer', 'jquery'], function () {
                    var h = th * 1.5;
                    var w = tw * 0.8;
                    var layer = layui.layer;
                    var $ = layui.jquery;
                    var TPName = $("#PrePlanName").val();//计划名称
                    var ID = CPID;//prePlanId;//集团id
                    //var TCID = prePlanId;// prePlanId;//上级计划id
                    var StartDateTime = $("#StartDateTime").val();
                    var EndDateTime = $("#EndDateTime").val();
                    var Duration = $("#Duration").val();
                    var RoomName = $("#CRName option:selected").text();
                    var RoomId = $("#CRName").val();
                    var TeacherName = $("#TrainTeacherName option:selected").text();
                    var TeacherId = $("#TrainTeacherName").val();
                    var TCOName = $("#TCOName").val();
                    var TrainUsers = $("#selectDatas2").val();

                    var TrainUserscontent1 = '';
                    for (var i = 0; i < vList1.length; i++) {
                        TrainUserscontent1 += vList1[i].CName + '|';
                    }
                    var TrainUserscontent2 = '';
                    for (var i = 0; i < vList2.length; i++) {
                        TrainUserscontent2 += vList2[i].CName + '|';
                    }
                    TrainUserscontent1 = TrainUserscontent1.substring(0, TrainUserscontent1.length - 1);
                    TrainUserscontent2 = TrainUserscontent2.substring(0, TrainUserscontent2.length - 1);
                    contentPage = "./traincoursepreview.html?TCOID=" + selectCurrentID + "&TrainPlanName=" + TPName + "&TrainCourseName=" + TCOName + "&StartDateTime=" + StartDateTime + "&EndDateTime=" + EndDateTime + "&Duration=" + Duration + "&CRName=" + RoomName + "&TrainTeacherName=" + TeacherName + "&TrainUsers=" + TrainUsers;// "&TrainUserscontent1=" + TrainUserscontent1 + "&TrainUserscontent2=" + TrainUserscontent2;
                    title = "课程预览";
                    layer.open({
                        title: false,
                        type: 2,
                        area: [w + "px", h + "px"],
                        btn: [' 确定  ', '  取消  '],
                        content: contentPage,
                        yes: function (index) {
                            layer.close(index);
                            $.ajax({
                                url: ApiUrl + contollerName + "/UpdatePlanStatus",
                                type: 'get',
                                cache: false,
                                headers: {
                                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                                },
                                data: { mark: 'C', value: '1', wherevalue: selectCurrentID },
                                success: function (data) {
                                    if (data.StatusCode == 200) {
                                        layer.alert("审核成功", { icon: 6 }, function (index) {
                                            layer.close(index);
                                            location.reload();
                                        })
                                    }
                                    else if (data.StatusCode == 403) {
                                        layer.alert(data.Info, function () {
                                            //location.href = './login.html';
                                            top.location.href = "http://" + top.location.host + "/login.html";
                                        })
                                    }
                                    else {
                                        layer.msg(data.Info);
                                    }
                                }
                            });

                        },
                        btn2: function (index) {
                            layer.close(index);
                            //layer.alert("cancel");
                        }
                    });

                });


            };
            //审核
            $("#check").click(function () {
                //审核 selectIDs
                //alert("审核");

                if (!GetOperate(3, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要审核的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == 1) {
                    layer.msg("选择的" + ModleNameTip + "已审核！");
                    return;
                }


                //$.ajax({
                //    url: ApiUrl + contollerName + "/UpdatePlanStatus",
                //    type: 'get',
                //    cache: false,
                //    headers: {
                //        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                //        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                //    },
                //    data: { mark: 'C', value: '1', wherevalue: selectCurrentID },
                //    success: function (data) {
                //        if (data.StatusCode == 200) {
                //            layer.alert("审核成功", { icon: 6 }, function (index) {
                //                layer.close(index);
                //                location.reload();
                //            })
                //        }
                //        else if (data.StatusCode == 403) {
                //            layer.alert(data.Info, function () {
                //                //location.href = './login.html';
                //                top.location.href = "http://" + top.location.host + "/login.html";
                //            })
                //        }
                //        else {
                //            layer.msg(data.Info);
                //        }
                //    }
                //});





                //region CJH 测试,
                showpreview();
            });
            //取消审核
            $("#uncheck").click(function () {
                if (!GetOperate(4, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要取消审核的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == "0") {
                    layer.msg("选择的" + ModleNameTip + "未审核！");
                    return;
                }

                layer.confirm('确定要取消审核吗?', function (index) {
                    //取消审核 selectIDs
                    //alert("已取消审核");


                    $.ajax({
                        url: ApiUrl + contollerName + "/UpdatePlanStatus",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { mark: 'C', value: "0", wherevalue: selectCurrentID },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert("取消审核成功", { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });


                    layer.close(index);
                });
            });
            //发布
            $("#release").click(function () {
                //alert("release");
                if (!GetOperate(4, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要发布的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == "0") {
                    layer.msg("选择的" + ModleNameTip + "未审核！");
                    return;
                }
                if (selectCurrentIsReleaseStatus == 1) {
                    layer.msg("选择的" + ModleNameTip + "已发布！");
                    return;
                }
                $.ajax({
                    url: ApiUrl + contollerName + "/UpdatePlanStatus",
                    type: 'get',
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { mark: 'R', value: '1', wherevalue: selectCurrentID },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            layer.alert("发布成功", { icon: 6 }, function (index) {
                                layer.close(index);
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                //发布 selectIDs
            });
            //取消发布
            $("#unrelease").click(function () {
                if (!GetOperate(6, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要取消发布的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsReleaseStatus == 0) {
                    layer.msg("选择的" + ModleNameTip + "未发布！");
                    return;
                }
                layer.confirm('确定要取消发布吗?', function (index) {
                    //conso.log("已取消发布");

                    $.ajax({
                        url: ApiUrl + contollerName + "/UpdatePlanStatus",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { mark: 'R', value: "0", wherevalue: selectCurrentID },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert("取消发布成功", { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });

                    layer.close(index);
                    //取消发布 selectIDs
                });
            });


            //end
        });
    </script>
</body>
</html>